/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package auctions;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;

/**
 *
 * @author hangsu
 */
public class S2PSB_test {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // System.out.println("main");
        int auction_environment = 0;
        int N = 8;
        int M = 5;
        ScheduleAuctionhouse house;
        Random r = new Random();
        ArrayList<ScheduleAgent> agents = new ArrayList<ScheduleAgent>();
        int lamda;
        double[] utils = new double[M];
        int simul_times = 1000;
        if (auction_environment == 0) {
            double[] avgProfit = new double [N];
            double[] avgRegret = new double[N];
            for(int simul = 0; simul<simul_times; simul++) {
                System.out.print("Simul #"+Integer.toString(simul)+"\n");
                agents.clear();
                for (int i = 0; i < N; i++) {
                    
                    lamda = r.nextInt(M) + 1;

                    for (int j = 0; j < M; j++) {
                        utils[j] = (double) r.nextInt(GlobalParameters.MaxPrice) + 1;
                    }
                    Arrays.sort(utils);
                    for(int k=0;k<M/2;k++){
                        double tmp_d = utils[k];
                        utils[k] = utils[M-1-k];
                        utils[M-1-k]= tmp_d;
                    }
                   
                    System.out.print("Agent #"+Integer.toString(i)+" Needs: "+Integer.toString(lamda) +" Utils: ");
                    for(int j=0; j<M; j++)
                        System.out.print(Double.toString(utils[j])+", ");
                    System.out.print("\n");
                                      
                    S2PSB_ScheduleAgent agent = new S2PSB_ScheduleAgent(i, N, M, lamda, M - 1, utils);
                    if (i == 0 ) {
                        agent.setStrategy(S2PSB_ScheduleAgent.S2PSB_strategy.BASELINE);
                    }
                    if (i == 1 ) {
                        agent.setStrategy(S2PSB_ScheduleAgent.S2PSB_strategy.WEIGHTED);
                    }
                    if( i == 2 ){
                        agent.setStrategy(S2PSB_ScheduleAgent.S2PSB_strategy.StraightMV);
                    }
                    if( i == 3 ) {
                        agent.setStrategy(S2PSB_ScheduleAgent.S2PSB_strategy.StraightMU);
                    }
                    
                    if( i == 4 ) {
                        agent.setStrategy(S2PSB_ScheduleAgent.S2PSB_strategy.CONF90);
                    }
                    
                    if( i == 5 ) {
                        agent.setStrategy(S2PSB_ScheduleAgent.S2PSB_strategy.CONF90);
                    }                
                                        
                    if( i == 6 ) {
                        agent.setStrategy(S2PSB_ScheduleAgent.S2PSB_strategy.CONF98);
                    }
                    
                    if( i == 7 ) {
                        agent.setStrategy(S2PSB_ScheduleAgent.S2PSB_strategy.CONF98);
                    }
                    
                    agent.setPricePrediction(GlobalParameters.PointPricePredict_S2PSB_StraightMV);
                    agent.setPriceDistribution(GlobalParameters.PriceDistPredict_S2PSB_StraightMU);
                    agent.computeReversedCDF();
                    ((S2PSB_ScheduleAgent)agent).setConf(0.98);
                    agents.add(agent);
                }
                house = new ScheduleSimultaneousAuctionHouse(M, AuctionType.SEALEDBID);
                house.setAgents(agents);
                house.startAuctions();
                //house.writeResult("result.xml");
                for(int i=0; i<N; i++){
                    avgProfit[i]+=agents.get(i).getBidderResult().getProfit();
                    avgRegret[i]+=((S2PSB_ScheduleAgent)agents.get(i)).computeRegret();
                }

            }
            System.out.println("=====EVALUATION=====");
            for (int i=0; i<8; i++) {
                avgProfit[i] /= simul_times;
                avgRegret[i] /= simul_times;
                System.out.println("Agent #"+Integer.toString(i)+ "("
                        +((S2PSB_ScheduleAgent)agents.get(i)).getStrategy().toString()
                        +") \tregret="+Double.toString(avgRegret[i])+ "\tprofit="
                        +Double.toString(avgProfit[i]));

            }
        }
        else{
        }
    }
}
